package com.khyr.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khyr.entity.HisRegistration;
import com.khyr.feign.UserFeign;
import com.khyr.service.RegisteredListService;
import com.khyr.vo.FindSchedulingListVo;
import com.khyr.vo.QMyPageDto;
import com.khyr.vo.R;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author ：Zhang
 * @date ：Created in 2025/3/14 14:27
 * @description：挂号列表
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/seeADoctor/RegisteredList")
public class RegisteredListController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private UserFeign userFeign;
    @Autowired
    private RegisteredListService registeredListService;
    /**
     * @create by: Zr
     * @description: 通过科室id，患者名，时间，时段，类型，挂号单状态查询挂号单
     * @create time: 2025/3/14 14:50
     * @param data
     * @return com.khyr.vo.R<com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.khyr.entity.HisRegistration>>
     */
    @PostMapping("/queryRegistrationForPage")
    public R<Page<HisRegistration>> queryRegistrationForPage(@RequestBody FindSchedulingListVo data) {
        return registeredListService.queryRegistrationForPage(data);
    }
    /**
     * @create by: Zr
     * @description: 根据挂号流水将挂号信息转为退号状态
     * @create time: 2025/3/14 14:58
     * @param registrationId
     * @return com.khyr.vo.R<java.lang.String>
     */
    @GetMapping("/doReturn/{registrationId}")
    public R<String> doReturn(@PathVariable String registrationId) {
        return registeredListService.doReturn(registrationId);
    }
    /**
     * @create by: Zr
     * @description: 根据挂号流水将挂号信息转为作废状态
     * @create time: 2025/3/14 15:04
     * @param registrationId
     * @return com.khyr.vo.R<java.lang.String>
     */
    @GetMapping("/doInvalid/{registrationId}")
    public R<String> doInvalid(@PathVariable String registrationId) {
        return registeredListService.doInvalid(registrationId);
    }
    /**
     * @create by: Zr
     * @description: 根据前端传入的类型对该用户的挂号信息进行查询，0全部，1待收费，待就诊，3就诊中，4完成，5退号
     * @create time: 2025/4/24 19:00
     * @param page
     * @param pageSize
     * @param orderState
     * @return com.khyr.vo.R<com.khyr.vo.QMyPageDto>
     */

    @GetMapping("/registrationList")
    public R<QMyPageDto> registrationList(Integer page, Integer pageSize, String orderState) {
        String token = request.getHeader("token");
        // 获取当前登录者的id
        String uId=userFeign.getPatientInfo(token).getData().getPatientId();
        return registeredListService.selectRegistrationListByStatus(page,pageSize,orderState,uId);
    }
}
